package com.example.haoqisystem.controller;

import com.example.haoqisystem.entity.Worker;
import com.example.haoqisystem.request.CreateWorkerRequest;
import com.example.haoqisystem.response.BaseResponse;
import com.example.haoqisystem.service.WorkerService;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户管理api")
@RestController
@RequestMapping("/worker")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class WorkerController {
    private final WorkerService workerService;

    @ApiOperation(value = "新增职工")
    @GetMapping("/add")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "账号", required = true),
            @ApiImplicitParam(name = "password", value = "密码", required = true),
            @ApiImplicitParam(name = "role", value = "角色职位（经理，执行人，现场工作人员，软件公司员工）"),
            @ApiImplicitParam(name = "roleId", value = "角色id(0:经理 1:执行人 2:现场工作人员 3:软件公司员工)")
    })
    public BaseResponse<Worker> add(CreateWorkerRequest request) {
        return workerService.add(request);
    }

    @ApiOperation(value = "职工登录")
    @GetMapping("/login")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "账号", required = true),
            @ApiImplicitParam(name = "password", value = "密码", required = true),
            @ApiImplicitParam(name = "role", value = "角色职位（经理，执行人，现场工作人员，软件公司员工）",required = true),
            @ApiImplicitParam(name = "roleId", value = "角色id(0:经理 1:执行人 2:现场工作人员 3:软件公司员工)",required = true)
    })
    public BaseResponse<Worker> login(String account,String password,String role,Integer roleId){
        return workerService.login(account,password,role,roleId);
    }

    @ApiOperation(value = "查询职工列表")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role", value = "角色职位（经理，执行人，现场工作人员，软件公司员工）")
    })
    public BaseResponse<List<Worker>> list(String role){
        return workerService.list(role);
    }

    //TODO:不需要职工详情?

    @ApiOperation(value = "删除职工")
    @GetMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "职工id")
    })
    public BaseResponse<String> delete(Long id){
        return workerService.delete(id);
    }
}


